package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.constant.Constants;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.ReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.NursingProjectVo;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {

    @Autowired
    private ReservationService reservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledReservationCount() {
        Long count = reservationService.getCancelledReservationCount();
        return success(count);
    }


    @GetMapping("/countByTime")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<List<Map<String, Object>>> countByTime(Long time) {
        List<Map<String, Object>> list = reservationService.countByTime(time);
        return success(list);
    }

    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult addReservation( @RequestBody ReservationDto reservationDto) {
        reservationService.addReservation(reservationDto);
        return success();
    }


    @ApiOperation(value = "分页查询我的预约数据")
    @GetMapping("/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query")
    })
    public ResponseResult<PageResponse<ReservationVo>> selectByPage(Integer pageNum,
                                                                       Integer pageSize,
                                                                       Integer status){
        PageResponse<ReservationVo> pageInfo = reservationService.selectByPage(pageNum, pageSize, status);
        return success(pageInfo);
    }


    @ApiOperation(value = "取消预约")
    @PutMapping("/{id}/cancel")
    public ResponseResult  cancleReservation(@PathVariable Long id){
        reservationService.cancleReservation(id);
        return success();
    }
}
